package src.com.foreknow.demo13;

import com.sun.org.apache.xpath.internal.operations.Or;

/**
 * 订单类 Order
 */
public class Order {
    private String OrderId;//订单编号
    private double total;//订单总额
    private OrderItem[] items;//保存多个订单项

    public Order(String OrderId){
        this.OrderId = OrderId;
        this.items = new OrderItem[3];
    }

    public String getOrderId() {
        return OrderId;
    }

    public void setOrderId(String orderId) {
        OrderId = orderId;
    }

    public double getTotal() {
        //调用计算总额的方法
        calTotal();
        return total;//返回计算后的总额
    }

    public void setTotal(double total) {
        this.total = total;
    }

    public OrderItem[] getItems() {
        return items;
    }

    //通过下标将OrderItem对象保存到OrderItem[]数组中
    public void setItems(OrderItem items,int i ) {
        this.items[i] = items;
    }

    /**
     * 计算订单总额 = 单价 * 数量
     */
    public void calTotal(){
        //对数组进行遍历
        if (items!=null){
            for (int i= 0; i<items.length;i++ ){
                total+= items[i].getNum()*items[i].getPprice();
            }
        }
        this.total = total;
    }

}






